﻿CREATE PROCEDURE [dbo].[EditorPasswordUpdate]
	@UserName nVarChar(50) = NULL,
	@EditorKey int = NULL,
	@PasswordSalt varChar(max),
	@PasswordHash varChar(max)
AS
	SET NOCOUNT ON

	IF (@UserName IS NULL AND @EditorKey IS NULL) OR (@UserName IS NOT NULL AND @EditorKey IS NOT NULL) BEGIN
		RAISERROR ('One of @UserName, @EditorKey must be non-null.', 15, 0)
		RETURN
	END


	UPDATE Editor SET 
		PasswordHash = @PasswordHash,
		PasswordSalt = @PasswordSalt
	WHERE 
		(@EditorKey IS NULL AND UserName = @UserName) OR
		(@UserName IS NULL AND EditorKey = @EditorKey)

	EXEC dbo.EditorPasswordSelect @UserName = @UserName, @EditorKey = @EditorKey

RETURN 0